package com.mx.web.service;

import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Query.query;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.mx.web.base.dao.BaseDao;
import com.mx.web.model.Article;
import com.mx.web.model.Pagination;

@Service
public class ArticleService extends BaseDao<Article>{
	
	private static final Logger logger = LoggerFactory.getLogger(ArticleService.class);
	  
	public Article push(Article article) {
		logger.info("执行ArticleService.push()方法");
		this.mongoTemplate.save(article);
		return article;
	}
	
	public Article load(String id) {
		logger.info("执行ArticleService.load()方法");
		Query query = query(where("id").is(id));
		return this.mongoTemplate.findOne(query, Article.class);
	}

	public Pagination<Article> list(int page) {
		logger.info("执行ArticleService.list()方法");
		return this.getPage(page, new Query());
	}
}